import * as type from '../types'
import {
    _getUserInfo,
    _getApplications,
    _logout
} from '@/api/user'

const state = {
    userInfo: '未知'
}

const actions = {
    // async fetchGetUserList(config, params) { // 获取用户列表
    //     let res = await _getUserList(params)
    //     return res && res.status ? res : false
    // },
    // async fetchUserInfo({ commit }, params) { // 获取用户信息
    //     let res = await _getLoginUser(params)
    //     if (!res && !res.status) return false
    //     let userInfo = await _getUserInfo(res.data.sn)
    //     if (!userInfo && !userInfo.status) return false;
    //     commit(type.USERINFO, userInfo.data)
    // },
    // async fetchLogout() { // 登出 
    //     const res = await _logout()
    //     if (res && res.status) {
    //         window.location.href = '/'
    //     }
    // }
    async getUserInfo({commit}) {
          let res =  await _getUserInfo()
          commit(type.USERINFO, res.name)
          localStorage.setItem("userName", res.name);
          localStorage.setItem("url", "http://" + res.url);
        
      }
}

const mutations = {
    [type.USERINFO] (state, data) {
        state.userInfo = data
    }
  }

export default {
    namespaced: true,
    state,
    actions,
    mutations
}